package com.iflysse.utils;

import java.io.IOException;
import java.io.Reader;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

/**
 * 获取SessionFactory
* @desc: lbjn
* @author: Administrator
* @createTime: 2014年11月13日 下午4:31:19
* @history:
* @version: v1.0
*/
public class MySessionFactory {

	/**
	 * SqlSessionFactory
	 */
	private static SqlSessionFactory sf;


	public static SqlSessionFactory getSessionFactory() {
		try {
			if (sf == null) {
				//使用reader读取xml配置文件
				Reader reader = Resources.getResourceAsReader("mybatis.xml");
				sf = new SqlSessionFactoryBuilder().build(reader);
			}
			return sf;
		} catch (IOException e) {
			e.printStackTrace();
			return null;
		}
	}
}
